package com.corpcredit.service.impl;

import java.util.ArrayList;
import java.util.List;

import com.corpcredit.dao.LookupDao;
import com.corpcredit.model.Glry;
import com.corpcredit.model.Jbqk;
import com.corpcredit.model.LabelValue;
import com.corpcredit.model.Role;
import com.corpcredit.service.LookupManager;


/**
 * Implementation of LookupManager interface to talk to the persistence layer.
 *
 * @author <a href="mailto:matt@raibledesigns.com">Matt Raible</a>
 */
public class LookupManagerImpl extends UniversalManagerImpl implements LookupManager {
    private LookupDao dao;

    /**
     * Method that allows setting the DAO to talk to the data store with.
     * @param dao the dao implementation
     */
    public void setLookupDao(LookupDao dao) {
        super.dao = dao;
        this.dao = dao;
    }

    /**
     * {@inheritDoc}
     */
    public List<LabelValue> getAllRoles() {
        List<Role> roles = dao.getRoles();
        List<LabelValue> list = new ArrayList<LabelValue>();

        for (Role role1 : roles) {
            list.add(new LabelValue(role1.getName(), role1.getName()));
        }

        return list;
    }

	public List findAllByJbqkID(Class clazz, Long jbqkID) {
		return dao.findAllByJbqkID(clazz, jbqkID);
	}

	public Object findByJbqkID(Class clazz, Long jbqkID) {
		return dao.findByJbqkID(clazz, jbqkID);
	}
	
	public String findByRyid(String clazz,String ryid)
	{
		if(ryid==null)
		{
			return "请输入人员ID";
		}
		try{
			Integer.parseInt(ryid);
		}catch(NumberFormatException ex)
		{
			return "人员ID选项请输入数字";
		}
		Object ro=dao.findByRyid(Glry.class.getName(), ryid);
		if(ro==null)
		{
			return "none";
			//return ryid+" the ryid is avalaible ";
		}else
		{
		    return "人员ID "+ryid+" 已在资料库中存在，请选择其它ID ";
		}
	}
	public List findGlryCwfzrByJqbkID(Long jbqkID)
	{
		return dao.findGlryCwfzrByJqbkID(jbqkID);
	}
	public List<Jbqk> findJbqks( String qyqc, String yyzzzch, String ssqy, Long hyflID )
	{
	    return dao.findJbqks( qyqc, yyzzzch, ssqy, hyflID  );
	}
}
